<template>
    <div class="container">
        <Header :left="true" title="提现账户设置"></Header>
        <el-form :model="form" ref="ruleForm" label-width="110px">
            <el-form-item prop="trueName" label="支付宝姓名" :rules="[{ required: true, message: '请输入支付宝姓名', trigger: 'blur' }]" >
                <el-input v-model="form.trueName" :maxlength="50" placeholder="请输入支付宝姓名"></el-input>
            </el-form-item>
            <el-form-item prop="alipayAccount" label="支付宝账户" :rules="[{ required: true, message: '请输入支付宝账户', trigger: 'blur' }]" >
                <el-input v-model="form.alipayAccount" placeholder="请输入支付宝账户"></el-input>
            </el-form-item>
            <div class="login-btn">
                <el-button style="width:100%" :loading="loading" type="primary" @click="confirmEvent">确认</el-button>
            </div>
        </el-form>
    </div>
</template>
<script>
import Header from '../../common/Header.vue';
export default {
    components:{Header},
    data:function(){
        return {
            loading:false,
            form:{
                trueName:'',
                alipayAccount:'',
            }
        };
    },
    created(){
        this.loadAccount();
    },
    methods:{
        loadAccount(){
            var that = this;
            that.$api.post('/channel/channelWithdrawDeposit/channelInfo.json',{}).then(data =>{
                if(data.data.code != '0'){
                    that.$message.error(data.data.msg);
                    return;
                }
                that.form.trueName = data.data.data.trueName;
                that.form.alipayAccount = data.data.data.alipayAccount;
            });
        },
        confirmEvent(){
            var that = this;
            this.$refs['ruleForm'].validate((valid) => {
                if (!valid) { return; }
                var body = {
                    trueName:that.form.trueName,
                    alipayAccount:that.form.alipayAccount
                }
                that.loading = true;
                that.$http.post('/channel/channelWithdrawDeposit/updateChannelInfo.json',body).then(data=>{
                    that.loading = false;
                    if(data.data.code != '0'){
                        that.$message.error(data.data.msg);
                        return;
                    }
                    that.$message.success('添加成功');
                    that.$router.go(-1);
                }).catch(error=>{
                    that.$message.error('请求出错');
                    that.loading = false;
                });
            });
        }

    }
}
</script>
<style scoped>
    .container{
        width: 100%;min-height: 100%;
        background: #F2F6FC;
        padding:10px;
    }
    .box{
        width: 100%;
        position: relative;
        background: #fff;
        padding: 10px;
    }
    .search-box{
        padding: 10px 130px 10px 10px;
        position: relative;
    }
    .search-box .search-right{
        position: absolute;
        top:9px;right:10px;
    }
    .store{
        width: 100%;
        padding: 0 150px 0 0;
        position: relative;
    }
    .store .store-desc{
        font-size: 14px;color: #606266;margin-top: 10px;
    }
    .store .store-right{
        position: absolute;
        top:10px;
        right:0px;
    }
    .footer-btns{
        position: fixed;
        width: 100%;
        left: 0;bottom: 60px;
        padding: 10px 10px 20px 10px;
        background: #fff;
        border-top: 1px solid #DCDFE6;
    }
</style>
